#include <map>

int pFunCmp(const void* pLeft, const void* pRight)
{
	char* pDataLeft = (char*)pLeft;
	char* pDataRight = (char*)pRight;

	return *pDataLeft - *pDataRight;
}

void TestIsAnagrame1(char* a, char* b)
{
	qsort(a, strlen(a), 1, pFunCmp);
	qsort(b, strlen(b), 1, pFunCmp);
	
	if (strcmp(a, b) == 0)
	{
		printf("is anagram\n");
	}
	else
	{
		printf("not anagram\n");
	}
}

void TestIsAnagrame2(char* a, char* b)
{
	int aCounter[26] = {0};
	int bCounter[26] = {0};

	for (int i = 0; i < strlen(a); ++i)
	{
		aCounter[a[i]- 'a']++;
	}
	for (int i = 0; i < strlen(b); ++i)
	{
		bCounter[b[i]- 'a']++;
	}

	for (int i = 0; i < sizeof(aCounter)/sizeof(aCounter[0]); ++i)
	{
		if (aCounter[i] != bCounter[i])
		{
			printf("not anagram\n");
			return;
		}
	}

	printf("is anagram\n");
}

int main(int argc, char **argv)
{
	char a[] = "art";
	char b[] = "tbr";

	TestIsAnagrame1(a, b);
	TestIsAnagrame2(a, b);
	return 0;
}